﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetDon.OA.Data.EntityClasses;
using NetDon.OA.Interface;
using NetDon.OA.Interface.CRM;
using NetDon.OA.Interface.Common;
using NetDon.Utilities;
using NetDon.WebControls;

namespace NetDon.OA.Portal.Admin
{
    [Navigation("系统管理", "在途天数维护")]
    public partial class GoodsTravelDaysManagement : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                PageQueryAdapter1.PageSize = 20;

                PageQueryAdapter1.PerformQuery();
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);




        }

        protected void PageQueryAdapter1_PerformGetCondition(object sender, PerformGetConditionEventArgs e)
        {
            var criteria = new GoodsTravelDaysConfigSearchCriteria
                               {
                                   DeliveryCity = this.ucProvinceCity.CityCode,
                                   DeliveryProvince =this.ucProvinceCity.ProvinceCode,
                                   RouteTypeId = this.ddlRouteTypeId.SelectedValue.ToGuid(),
                                   AreaId = CurrentApplicationContext.CompanyId
                               };

            e.Condition = criteria;
        }

        protected void PageQueryAdapter1_PerformGetRecordCount(object sender, PerformGetRecordCountEventArgs e)
        {
            var service = ServiceContainer.GetService<IGoodsTravelDaysConfigService>();
            e.RecordCount = service.GetGoodsTravelDaysConfigCount((GoodsTravelDaysConfigSearchCriteria)e.Condition);
        }

        protected void PageQueryAdapter1_PerformGetPageData(object sender, PerformGetPageDataEventArgs e)
        {
            var service = ServiceContainer.GetService<IGoodsTravelDaysConfigService>();
            e.DataSource = service.SearchGoodsTravelDaysConfigDatasByCondition((GoodsTravelDaysConfigSearchCriteria)e.Condition,
                                                                      gridCustomerInfoList.SortExpression,
                                                                      gridCustomerInfoList.SortDirection, e.PageSize,
                                                                      e.PageIndex);
        }

        protected void btnReload_Click(object sender, EventArgs e)
        {
            PageQueryAdapter1.ReloadCurrentPage();
        }


        protected void btnSearch_Click(object sender, EventArgs e)
        {
            PageQueryAdapter1.PerformQuery();
        }

        protected void btnDeleteDemand_Click(object sender, EventArgs e)
        {
            var service = ServiceContainer.GetService<IGoodsTravelDaysConfigService>();
            var customerId = fieldCustomerId.Value.ToGuid();

            bool result = service.RemoveGoodsTravelDaysConfig(customerId);

            if (result)
            {
                PageQueryAdapter1.PerformQuery();
                Alert("删除在途天数信息成功!");
            }
            else
            {
                Alert("删除在途天数信息失败！");
            }
        }

  



        protected string GetGoodsTravelDays(object goodsTravelDays, object goodsTravelDaysUnit)
        {
            if (MiscUtilities.IsNull(goodsTravelDays)) return string.Empty;
            return goodsTravelDays + " " +
                   EnumUtilities.GetDescription(
                       (GoodsTravelDayUnit)
                       Enum.Parse(typeof(GoodsTravelDayUnit), (goodsTravelDaysUnit ?? 0).ToString()));


        }


    }
}




